home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 40 / Amiga Format CD40 (1999-05-11)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-06].iso / -readerstuff- / paul_qureshi / info / colourspaceconversions.txt < prev    next >
Text File  |  1999-03-27  |  53KB  |  1,241 lines

  1.  
  2. ------------------------------------------------------------------------
  3.               Colour Space Conversions.
  4. ------------------------------------------------------------------------
  5.  
  6. Complied by Alan Roberts (Alan.Roberts@rd.bbc.co.uk) and Adrian Ford 
  7. (ajoec1@westminster.ac.uk) This document may be reproduced and 
  8. distributed freely, provided that you do not alter it in any way,
  9. credit its source and that no charge is made for it. 
  10.  
  11. ------------------------------------------------------------------------
  12.  
  13. This document, containing equations relating to colour spaces
  14. and colour transforms, is presented as an alternative to David Bourgin's
  15. ColorSpaces FAQ. Both of the principle authors of this document have 
  16. contibuted extensivly to the ColorSpaces FAQ but have become unhappy at 
  17. the errors it contained and its maintainers unwillingness to correct them. 
  18. We recommend that this document is read in conjunction with 
  19. Charles Poynton's documents, GammaFAQ.pdf and ColorFAQ.pdf for a more 
  20. complete introduction to colour systems. 
  21.  
  22. They are available from:
  23.  
  24.   ftp.inforamp.net/pub/users/poynton/doc/Colour/
  25.  
  26. in Acrobat PDF, PostScript and ASCII text formats. If you have a web
  27. browser, consult Poynton's Gamma and Colour FAQ page;
  28.  
  29.   http://www.inforamp.net/~poynton/Poynton-colour.html
  30.  
  31. This document can always be found at
  32.  
  33.   ftp.westminster.ac.uk in directory /pub/itrg
  34.  
  35. Please send comments to Charles Poynton (poynton@inforamp.net), Alan
  36. Roberts (Alan.Roberts@rd.bbc.co.uk) or Adrian Ford (ajoec1@wmin.ac.uk)
  37. as appropiate.
  38.  
  39. Date of this edition: 5 May 1995
  40. -----------------------------------------------------------------------
  41.  
  42.                        Colour Equations FAQ.
  43.                        ---------------------
  44.  
  45.  
  46. Contents:
  47.  
  48.  Section [1] Some definitions and explanations.
  49.   [1.1] What is the correct way to describe colour that we see?
  50.   [1.2] What is a colour space?
  51.   [1.3] Why is there more than one colour space?
  52.   [1.4] What's the difference between device dependent and device 
  53.     independent?
  54.   [1.5] What is a colour gamut?
  55.   [1.6] What is the CIE System?
  56.   [1.7] What colour space should I use?
  57.  Section [2] Gamma and linearity.
  58.  Section [3] Grassman's Laws of additive colour mixture.
  59.  Section [4] Tristimuli, Chromaticity, and colorimetric systems
  60.   [4.1] CIE XYZ (1931)
  61.   [4.2] CIE YUV (1960)
  62.   [4.3] CIE YU'V'
  63.   [4.4] CIE L*u*v*
  64.   [4.5] CIE LAB
  65.   [4.6] CMC colour difference formula.
  66.  Section [5]   Computer Graphics Colour Spaces.
  67.   [5.1] Computer RGB colour space.
  68.   [5.2] CMY(K) (Cyan Magenta Yellow (Black))
  69.   [5.3] HSL and HSV (Hue Saturation and Lightness / Value)
  70.  Section [6]   TV and allied non-linear systems
  71.   [6.1] European Y'U'V' (EBU)
  72.   [6.2] American Y'I'Q'
  73.   [6.3] SMPTE-C RGB
  74.   [6.4] ITU.BT-601 Y'CbCr
  75.   [6.5] ITU.BT-709 HDTV studio production in Y'CbCr
  76.   [6.6] SMPTE-240M Y'PbPr
  77.   [6.7] Kodak PhotoYCC colour space for PhotoCD images.
  78.  Section [7] Colour appearence.
  79.  Section [8] The references and bedtime reading.
  80.  Section [9] Footnotes & Disclaimer.
  81.  
  82. Section [1] Some definitions and explanations.
  83.  
  84. This is a chatty bit about colour spaces related to computers.
  85.  
  86. [1.1] What is the correct way to describe colour that we see?
  87.  
  88. Colour is described by three attributes. The following terms have been 
  89. defined by the CIE (see 1.6) and are given in Hunt's book "Measuring 
  90. Colour":
  91.  
  92. brightness    - the human sensation by which an area exhibits more or less 
  93.         light.
  94. Hue           - the human sensation according to which an area appears 
  95.         to be similar to one, or to proportions of two, of the 
  96.         perceived colours red, yellow, green and blue.
  97. Colourfulness - the human sensation according to which an area appears to 
  98.         exhibit more or less of its hue.
  99.  
  100. lightness     - the sensation of an area's brightness relative to a reference
  101.         white in the scene.
  102. chroma        - the colourfulness of an area relative to the brightness of a
  103.         reference white.
  104. saturation    - the colourfulness of an area relative to its brightness.
  105.  
  106. A `colour' is a visual sensation produced by a specific SPD (spectral
  107. power distribution) incident on the retina. The eye senses colour using
  108. three classes of wavelength. This mechanism means that two different 
  109. SPD's may produce the same visual sensation - an effect known as 
  110. metamerism. 
  111. A point to note, is that although the eye senses colour roughly 
  112. according to red, green and blue light (trichromatic theory), higher 
  113. visual processes in the brain code colour according to the opponent 
  114. process theory using the opponent pairs roughly termed red - green, 
  115. blue - yellow and black - white.
  116.  
  117. [1.2] What is a colour space?
  118.  
  119. A colour space is a method by which we can specify, create and visualise 
  120. colour. As humans, we may define a colour by its attributes of brightness, 
  121. hue and colourfulness. A computer will describe a colour stimulus in terms 
  122. of the excitations of red, green and blue phosphors on the CRT faceplate. 
  123. A printing press descibes a colour stimulus in terms of the reflectance and 
  124. absorbance of cyan, magenta, yellow and black inks on the paper. 
  125. Such a colour is usually specified by using three coordinates, or 
  126. attributes, which represent its position within a specific colour space. 
  127. These coordinates do not tell us what the colour looks like, only where 
  128. the colour is located within a particular colour space.
  129.  
  130. [1.3] Why is there more than one colour space?
  131.  
  132. Different colour spaces are better for different applications, some 
  133. equipment has limiting factors that dictate the size and type of colour 
  134. space that can be used.  Some colour spaces are perceptually linear, 
  135. i.e. a 10 unit change in stimulus will produce the same change in 
  136. perception wherever it is applied. Many colour spaces, particularly in 
  137. computer graphics are not linear in this way. Some colour spaces are 
  138. intuitive to use, i.e. it is easy for the user to navigate within them 
  139. and creating desired colours is relatively easy. Finally, some colour 
  140. spaces are device dependent while others are not - i.e device independent.
  141.  
  142. [1.4] What's the difference between device dependent and device independent?
  143.  
  144. A device dependent colour space is a colour space where the resultant colour 
  145. depends on the equipment and the set-up used to produce it. For example the 
  146. colour produced using pixel values of rgb = 250,134,67 will alter as 
  147. you change the brightness and contrast on your display. In the same way if 
  148. you swap your monitor the red, green and blue phosphors will have slightly 
  149. different characteristics and the colour produced will change. Thus RGB is a 
  150. colour space that is dependent on the system being used, it is device 
  151. dependent. A device independent colour space is one where the coordinates 
  152. used to specify the colour will produce the same colour wherever they are 
  153. applied. An example of a device independent colour space is the CIE L*a*b* 
  154. colour space (known as CIELab and based on the human visual system). 
  155.  
  156. Another way of looking a device dependency is to imagine an RGB cube within 
  157. a colour space representing all possible colours (for example a CIE based
  158. colour space). We define a colour by the values on the three axes, however 
  159. the exact colour will depend on the position of the cube within the 
  160. perceptual colour space, move the cube (by changing the set-up) and the 
  161. colour will change.
  162.  
  163. Some device dependent colour spaces have their position within CIE space 
  164. defined, these are known as device calibrated colour spaces and are a kind 
  165. of half way house between dependent and independent colour spaces. For 
  166. example, a graphics file that contains colorimetric information,
  167. i.e. the white point, transfer functions, and phosphor chromaticities,
  168. would enable device dependent RGB data to be modified for whatever
  169. device was being used - i.e. calibrated to specific devices.
  170.  
  171. [1.5] What is a colour gamut?
  172.  
  173. A colour gamut is the area enclosed by a colour space in three dimensions.
  174. It is usual to represent the gamut of a colour reproduction
  175. system graphically as the range of colours available in some
  176. device independent colour space. Often the gamut will be represented in 
  177. only two dimensions, for example on a CIE u'v' chromaticity 
  178. diagram (see 4.3). 
  179.  
  180. [1.6] What is the CIE System?
  181.  
  182. The CIE has defined a system that classifies colour according to the HVS 
  183. (the human visual system). Using this system we can specify any colour in 
  184. terms of its CIE coordinates. 
  185.  
  186. The CIE system works by weighting the SPD of an object in terms of three
  187. colour matching functions. These functions are the sensitivities of a
  188. standard observer to light of different wavelengths. The weighting is 
  189. performed over the visual spectrum, from around 360nm to 830nm in set 
  190. intervals. However, the illuminant, and lighting and viewing geometry are 
  191. carefully defined, since these all affect the appearance of a particular
  192. colour. This process produces three CIE tri-stimulus values, XYZ, which 
  193. are the building blocks from which many colour measurements are made.
  194.  
  195. [1.7] What colour space should I use?
  196.  
  197. That depends on what you want to do, but here is a list of the pros and cons 
  198. of some of the more common, computer related, colour spaces;
  199.  
  200. RGB (Red Green Blue)
  201.  
  202. Additive colour system based on trichromatic theory, used by CRT 
  203. displays where proportions of excitation of red, green and blue emitting 
  204. phosphors produce colours when visually fused. Easy to implement, non linear, 
  205. device dependent, unintuitive, common (used in television cameras, computer 
  206. graphics etc).
  207.  
  208. CMY(K) (Cyan Magenta Yellow (Black))
  209.  
  210. Subtractive colour. Used in printing and photography. Printers often include 
  211. the fourth component, black ink, to improve the colour gamut (by increasing 
  212. the density range), improving blacks, saving money and speeding drying (less 
  213. ink to dry). Fairly easy to implement, difficult to transfer *properly* from 
  214. RGB (simple transforms are, well, simple), device dependent, non-linear, 
  215. unintuitive.
  216.  
  217. HSL (Hue Saturation and Lightness)
  218.  
  219. This represents a wealth of similar colour spaces, alternatives include HSI 
  220. (intensity), HSV (value), HCI (chroma / colourfulness),  HVC, TSD (hue 
  221. saturation and darkness) etc etc. Most of these colour spaces are linear 
  222. transforms from RGB and are thus, device dependent, non-linear but very 
  223. intuitive. In addition the separation of the luminance component has 
  224. advantages in image processing and other applications. (But take care, the 
  225. complete isolation of the separate components will require a space optimised 
  226. for your device. See later notes on CIE colour spaces) 
  227.  
  228. YIQ, YUV, YCbCr, YCC  (Luminance - Chrominance)
  229.  
  230. These are the television transmission colour spaces, also known as
  231. transmission primaries. (YIQ and YUV are analogue for NTSC and PAL, and 
  232. YCbCr is digital). They separate luminance from chrominance (lightness 
  233. from colour) and are useful in compression and image processing applications. 
  234. They are device dependent and, unless you are a TV engineer, unintuitive. 
  235. Kodaks PhotoCD system uses a type of YCC colour space, PhotoYCC, which is a 
  236. device calibrated colour space.
  237.  
  238. CIE 
  239.  
  240. There are two CIE based colour spaces, CIELuv and CIELab. They are near 
  241. linear (as close as any colour space is expected to sensibly get), device 
  242. independent (unless your in the habit of swapping your eye balls with aliens), 
  243. but not very intuitive to use. 
  244.  
  245. From CIELuv you can derive CIELhs or CIELhc where h is the hue (an angle), 
  246. s the saturation and c the chroma. This is more intuitive to work with when
  247. specifying colours. CIELuv also has an associated chromaticity diagram, a two 
  248. dimensional chart which makes additive colour mixing very easy to visualise, 
  249. hence CIELuv is widely used in additive colour applications, like television.
  250.  
  251. CIELab has no associated two dimensional chromaticity diagram and no 
  252. correlate of saturation so only CIELhc can be used.
  253.  
  254. Section [2] Gamma and linearity.
  255.  
  256. Many image processing operations, and also colour space transforms that 
  257. involve device independent colour spaces, like the CIE system based
  258. ones, must be performed in a linear luminance domain. 
  259. By this we really mean that the relationship between pixel 
  260. values specified in software and the luminance of a specific area on the CRT 
  261. display must be known. In most cases the CRT will have a non-linear response. 
  262. The luminance of a CRT is generally modeled using a power function with an 
  263. exponent, gamma, somewhere between 2.2 (NTSC and SMPTE specifications) and 
  264. 2.8 (as given by Hunt and Sproson). Recent measurements performed at the BBC 
  265. in the UK (by Richard Salmon and Alan Roberts) have shown that the actual 
  266. value of gamma is very dependent upon the accurate setting of the CRT's black 
  267. level. For correctly set-up CRT's, gamma is 2.35 +/- 0.1. This relationship 
  268. is given as follows;
  269.  
  270. Luminance = voltage ^ gamma
  271.  
  272. Where luminance and voltage are normalised. 
  273.    
  274. In order to display image information as linear luminance  we need to modify 
  275. the voltages sent to the CRT. This process stems from television systems
  276. where the camera and receiver had different transfer functions (which,
  277. unless corrected, would cause problems with tone reproduction). The
  278. modification applied is known as gamma correction and is given below;
  279.  
  280. New_Voltage = Old_Voltage ^ (1/gamma)
  281.  
  282. (both voltages are normalised and gamma is the value of the exponent of the 
  283. power function that most closely models the luminance-voltage relationship 
  284. of the display being used.)
  285.  
  286. For a colour computer system we can replace the voltages by the pixel values 
  287. selected, this of course assumes that your graphics card converts digital 
  288. values to analogue voltages in a linear way. (For precision work you should 
  289. check this). The colour relationships are;
  290.  
  291.     Red  = a* (Red' ^gamma) +b
  292.     Green= a* (Green' ^gamma) +b
  293.     Blue = a* (Blue' ^gamma) +b
  294.  
  295. where Red', Green', and Blue' are the normalised input RGB pixel values and 
  296. Red, Green, and Blue are the normalised gamma corrected signals sent to the 
  297. graphics card. The values of the constants a and b compensate for the overall 
  298. system gain and system offset respectively. (essentially gain is contrast and 
  299. offset is intensity.) For basic applications the value of a, b and gamma can 
  300. be assumed to be consistent between colour channels, however for precise 
  301. applications they must be measured for each channel separately.
  302.        
  303. A more accurate description of the gamma relationship has recently been given 
  304. in a paper by Berns. See also Charles Poynton's paper and his
  305. document GammaFAQ. The implementation of gamma correction for television
  306. standards is discussed more fully in section 6.
  307.  
  308. Note: Gamma correction performed in integer maths is prone to large 
  309. quantisation errors. For example, applying a gamma correction of 1/2.2 to 
  310. an image with an original gamma of one (linear luminance) produces a drop 
  311. in the number of grey levels from 245 to 196. Therefore take care not to 
  312. alter the transfer characteristics more than is necessary, if you need to 
  313. gamma correct images try to keep the originals so that you can pass them 
  314. on to others without passing on the degradations that you've produced ;-). 
  315. In addition, any implementation of gamma correction which takes no account 
  316. of the transfer function of the image acquisition system, is an incomplete 
  317. implementation.
  318.  
  319. Section [3]  Grassman's Laws of additive colour mixture.
  320.  
  321. Any colour (source C) can be matched by a linear combination of three other 
  322. colours (primaries eg. RGB), provided that none of those three can be matched 
  323. by a combination of the other two. This is fundamental to colorimetry and is 
  324. Grassman's first law of colour mixture. So a colour C can be matched by Rc 
  325. units of red, Gc units of green and Bc units of blue. The units are can be 
  326. measured in any form that quantifies light power.
  327.  
  328.    C = Rc(R) + Gc(G) + Bc(B)
  329.  
  330. A mixture of any two colours (sources C1 and C2) can be matched by linearly 
  331. adding together the mixtures of any three other colours that individually 
  332. match the two source colours. This is Grassman's second law of colour 
  333. mixture. It can be extended to any number of source colours.
  334.  
  335.    C3(C3) = C1(C1) + C2(C2) = [R1+R2](R) + [G1+G2](G) + [B1+B2](B)
  336.  
  337. Colour matching persists at all luminances. This is Grassman's third law. It 
  338. fails at very low light levels where rod cell vision (scoptopic) takes over 
  339. from cone cell vision (photopic).
  340.  
  341.    kC3(C3) = kC1(C1) + kC2(C2).
  342.  
  343. The symbols in square brackets are the names of the colours, and not numerical 
  344. values. The equality sign should not be used to signify an identity, in 
  345. colorimetry it means a colour matching, the colour on one side of the equality 
  346. looks the same as the colour on the other side.
  347.  
  348. These laws govern all aspects of additive colour work, but they apply only 
  349. signals in the "linear-light" domain. They can be extended into subtractive 
  350. colour work.
  351.  
  352. Section [4]   Tristimuli, Chromaticity, and colorimetric systems
  353.  
  354. A colour can be described as a mixture of three other colours or "Tristimuli". 
  355. Typically RGB for CRT based systems (TV, computer) or XYZ (fundamental 
  356. measurements). The amounts of each stimulus define the colour. However, it is 
  357. frequently useful to separate the colour definition into "luminance" and 
  358. "chromaticity". Lower case is always used to signify chromaticity coordinates, 
  359. upper case always signifies tristimulus values (or amounts of the primaries). 
  360. Chromaticity coordinates can be plotted on a two-dimensional diagram that 
  361. defines all the visible colours, luminance is normal to that diagram.
  362.  
  363. [4.1] CIE XYZ (1931)
  364.  
  365. The CIE XYZ (1931) system is at the root of all colorimetry. It is defined 
  366. such  that all visible colours can be defined using only positive values, 
  367. and, the Y value is luminance. Consequently, the colours of the XYZ 
  368. primaries themselves are not visible. The chromaticity diagram is highly 
  369. non-linear, in that a vector of unit magnitude representing the difference 
  370. between two chromaticities is not uniformly visible. A colour defined in this 
  371. system is referred to as Yxy. A third coordinate, z, can also be defined but 
  372. is redundant since x+y+z=1 for all colours.
  373.  
  374.     x = X / (X + Y + Z)
  375.     y = Y / (X + Y + Z)
  376.  
  377. [4.2] CIE YUV (1960)
  378.  
  379. This is a linear transformation of Yxy, in an attempt to produce a 
  380. chromaticity diagrams in which a vector of unit magnitude (difference between 
  381. two points representing two colours) is equally visible at all colours. Y is 
  382. unchanged from XYZ or Yxy. Difference non-uniformity is reduced considerably, 
  383. but not enough. A third coordinate, w, can also be defined but is redundant.
  384.  
  385.     u = 2x / (6y - x + 1.5)
  386.     v = 3y / (6y - x + 1.5)
  387.  
  388.  
  389. [4.3] CIE YU'V'
  390.  
  391. This is another linear transformation of Yxy. Y remains unchanged. 
  392. Difference non-uniformity is further reduced, but still not enough. Again, 
  393. a third coordinate, w', can be defined, but is redundant.
  394.  
  395.     u' = u    = 2x / (6y - x + 1.5)
  396.     v' = 1.5v = 4.5y / (6y - x + 1.5)
  397.  
  398.  
  399. [4.4] CIE L*u*v*
  400.  
  401. This is based on CIE Yu'v' (1976) and is a further attempt to linearise 
  402. the perceptibility of unit vector colour differences. It is a non-linear 
  403. colour space, but the conversions are reversible. Colouring information is 
  404. centered on the colour of the white point of the system, subscript n, (D65 
  405. in most TV systems). The non-linear relationship for Y* is intended to mimic 
  406. the logarithmic response of the eye.
  407.  
  408.     L* = 116*((Y/Yn)^(1/3))     for Y/Yn>0.008856
  409.     L* = 903.3*Y/Yn             for Y/Yn<=0.008856
  410.     u* = 13*(L*)*(u'-u'n)
  411.     v* = 13*(L*)*(v'-v'n)
  412.  
  413. L* scales from 0 to 100 for relative luminance (Y/Yn) scaling 0 to 1.
  414.  
  415. There are three other, more meaningful polar parameters which more closely 
  416. match  the human visual experience than do the Cartesian parameters.
  417.  
  418.     Chroma                     C* = (u*^2 + v*^2) ^ 0.5
  419.     Hue                       huv = arctan(v* / u*)
  420.     Psychometric Saturation   suv = C* / L*
  421.  
  422. Hue is an angle in four quadrants.
  423.  
  424. [4.5] CIE LAB
  425.  
  426. This is based directly on CIE XYZ (1931) and is another attempt to linearise 
  427. the perceptibility of unit vector colour differences. Again, it is non-linear, 
  428. and the conversions are still reversible. Colouring information is referred 
  429. to the colour of the white point of the system, subscript n. The non-linear 
  430. relationships for L* a* and b* are the same as for CIELUV and are intended 
  431. to mimic the logarithmic  response of the eye.
  432.  
  433.     L*=116*((Y/Yn)^(1/3))       for Y/Yn>0.008856
  434.     L*=903.3*Y/Yn               for Y/Yn<=0.008856
  435.     a*=500*(f(X/Xn)-f(Y/Yn))
  436.     b*=200*(f(Y/Yn)-f(Z/Zn))
  437.     where f(t)=t^(1/3)          for t>0.008856
  438.       f(t)=7.787*t+16/116   for t<=0.008856
  439.  
  440. Again, L* scales from 0 to 100.
  441.  
  442. Again, there are polar parameters that more closely match the visual 
  443. experience of colours.
  444.  
  445.     Chroma C*  = (a*^2 + b*^2)^ 0.5
  446.     Hue    hab = arctan(b*/a)
  447.  
  448. Hue is an angle in four quadrants, and there is no saturation term in this 
  449. system.
  450.  
  451.  
  452. [4.6] CMC colour difference formula.
  453.  
  454. The CMC colour difference formula is better than CIE Lab for evaluating
  455. small colour differences.
  456.  
  457. Colour difference = [(D_L / l * Sl)^2 + (D_C / c * Sc)^2 + (D_H / Sh)^"2]^0.5
  458.  
  459. where; Sl = 0.040975L / (1+0.01765L) unless L < 16 when Sl = 0.511
  460.        Sc = 0.0638C / (1+0.0131C) + 0.638
  461.        Sh = (f*T + 1 - f)Sc
  462.  
  463. where; f = (C^4 / (C^4 + 1900))^0.5
  464.        T = 0.36 + | 0.4 cos(h + 35| unless h is between 164 and 345
  465.      degrees when
  466.         T = 0.56 + | 0.2 cos(h + 168) |
  467.  
  468. D_L is delta E star, D_C is delta C star, D_H delta H star, L is L star
  469. and h hue angle.a:
  470.  
  471. for predicting colour differences, the weights l and c are set to unity,
  472. and the colour difference is referred to as the CMC(1:1) difference.
  473.  
  474. Section [5]   Computer Graphics Colour Spaces.
  475.  
  476. Traditionally colour spaces for computer graphics have been designed for
  477. specific devices - RGB for displays or CMY for printers. As such they
  478. are device dependent (and meaningless if applied to different devices or
  479. the same device in different conditions). Most computer graphics colour
  480. spaces are perceptually non-linear, i.e. colour differences vary
  481. throughout the space, this makes them inefficient for coding colour
  482. information. Another problem is that they can be unintuitive, by this we
  483. mean that a novice may find it difficult to specify a desired colour -
  484. for example selecting the colour brown in an RGB space.
  485.  
  486. A caveat. 
  487.  
  488. The transforms in this section are generally simplifications of the
  489. real world. We strongly recommend reading the references at the end of
  490. this FAQ as well as Charles Poynton's ColorFAQ and GammaFAQ.
  491.  
  492. We assume all values are normalised to 1 unless otherwise stated.
  493.  
  494. [5.1] Computer RGB colour space.
  495.  
  496. This is the colour space produced on a CRT (or similar) display when
  497. pixel values are applied to a graphics card. To convert RGB pixel values
  498. to CIE XYZ tri-stimulus values is a two stage process.
  499.  
  500. 1) Calculate the displayed luminance for each pixel value, this is done
  501. by applying the gamma correction factor to the signal. Ideally this
  502. should be calculated for each channel independently, (see sections 2 and 6).
  503.  
  504. 2) Perform a matrix transform from the linear RGB to CIE XYZ values.
  505. This transform takes the following form.
  506.  
  507.        |X|       |Xr  Xg  Xb|     |R| 
  508.        |Y|   =   |Yr  Yg  Yb|  *  |G|
  509.        |Z|       |Zr  Zg  Zb|     |B|
  510.  
  511. where Xr,Yr,Zr, are the CIE XYZ tristimulus values of the red phosophor
  512. at full emission measured from the CRT faceplate.
  513. Xg,Yg,Zg, are the CIE XYZ tristimulus values of the green phosophor
  514. at full emission measured from the CRT faceplate.
  515. and Xb,Yb,Zb, are the CIE XYZ tristimulus values of the blue phosophor
  516. at full emission measured from the CRT faceplate.
  517. R, G and B are the corrected pixel values obtained from the previous step 
  518. (by gamma correction).
  519. X, Y and Z are the resultant CIE XYZ tristimulus values of the displayed 
  520. colour.
  521.  
  522. To convert from XYZ to RGB use the inverse matrix.
  523.  
  524.        |R|       |Xr  Xg  Xb|(-1)     |X| 
  525.        |G|   =   |Yr  Yg  Yb|     *   |Y|
  526.        |B|       |Zr  Zg  Zb|         |Z|
  527.  
  528. In section 6.1 this relationship is given for a typical television system,
  529. for this system the matrix to convert RGB to XYZ is as follows...
  530.  
  531.        |X|    |0.431 0.342 0.178|      |R|
  532.        |Y| =  |0.222 0.707 0.071|   *  |G|
  533.        |Z|    |0.020 0.130 0.939|      |B|
  534.  
  535. which gives;
  536.  
  537.         X = 0.431*R + 0.342*G + 0.178*B
  538.         Y = 0.222*R + 0.707*G + 0.071*B
  539.         Z = 0.020*R + 0.130*G + 0.939*B
  540.  
  541. Which, given specific RGB values, can be used to calculate CIE XYZ.
  542. Source code is given in Travis' book for matrix transforms between RGB and
  543. CIE XYZ. (see references).
  544.  
  545. Often, it is not possible to measure the phosphors of your particluar 
  546. display, as this requires either a spectroradiometer or a colorimeter.
  547. You can get round this if you have published data for your display's 
  548. CIE xy chromaticity coordinates of each phosphor and the white point.
  549. Since the CIE Y tristimulus value always has a value of one you can
  550. calculate CIE XYZ for the white point and then (assuming additivity)
  551. CIE XYZ for the three phosphors by solving the three simultanous 
  552. equations.
  553.  
  554. [The white point of a display system is the displayed colour that is
  555. produced when all three channels are driven to maximum. (eg RGB = 255,
  556. 255,255). The white point is usually expressed as either CIE xy 
  557. chromaticity coordinates or a correlated colour temperature in Kelvin.]
  558.  
  559. There can be problems with converting between RGB and XYZ which result
  560. in differences between values calculated and those measured from the 
  561. screen. Assuming that the correction for the display gamma is correct 
  562. and that you have the right CIE XYZ tristimulus values the following
  563. may apply:
  564.  
  565.   spatial non-linearity - the colour on a CRT display often differs with
  566.                           the spatial location across the faceplate.
  567.   channel dependence    - there may be interactions between channels,
  568.                           for instance the green signal may cause 
  569.                           excitation in the red phosphors.
  570.   spatial dependence    - the exact displayed colour often depends on what
  571.                           else is being displayed on screen at the same 
  572.                           time. For instance a central red patch will have
  573.                           a different colour depending on whether the
  574.                           surround is black or white. (Note this is in
  575.                           addition to visual effects in the HVS.)
  576.   lack of additivity    - many displays do not strictly obey the rules of
  577.                           additivity, the sum of the measurements of red
  578.                           green and blue differs from the measured white.
  579.                           Ideally they should be identical. (See section 3).
  580.  
  581. These errors mean that although greater accuracy can be obtained by using
  582. the actual display system transfer function rather than gamma (which is an
  583. approximation) the effort probably isn't worth it.
  584. See Berns et al for a details of possible problems and descriptions of some 
  585. solutions, also Sproson for more detailed theory of RGB to CIE conversions 
  586. in television systems.
  587.  
  588.                          
  589. [5.2] CMY(K) (Cyan Magenta Yellow (Black))
  590.  
  591. CMY(K) is device dependent, unintuitive and perceptually non-linear; 
  592.  
  593. To convert from RGB to CMY for printing, the simplest method is to
  594. convert from RGB to CIE XYZ and then from CIE XYZ to CMY(K). This is not
  595. a trivial process and ideally takes into consideration other factors -
  596. such as the printing inks being used, the type of press and screening,
  597. the paper, viewing conditions, lighting, etc. 
  598.  
  599. Simple (and incorrect) transforms for RGB to CMY are given below;
  600.  
  601. RGB to CMY                         
  602. Cyan    = 1-Red                    
  603. Magenta = 1-Green                 
  604. Yellow  = 1-Blue                  
  605.  
  606. CMY to RGB                   
  607. Red   = 1-Cyan
  608. Green = 1-Magenta 
  609. Blue  = 1-Yellow
  610.  
  611. CMY to CMYK                             
  612. Black   = minimum (Cyan,Magenta,Yellow) 
  613. Cyan    = (Cyan-Black)/(1-Black)                
  614. Magenta = (Magenta-Black)/(1-Black)     
  615. Yellow  = (Yellow-Black)/(1-Black)      
  616.  
  617. CMYK to CMY
  618. Cyan    = minimum(1,Cyan*(1-Black)+Black)
  619. Magenta = minimum(1,Magenta*(1-Black)+Black)
  620. Yellow  = minimum(1,Yellow*(1-Black)+Black)
  621.  
  622. These transforms may be sufficient if you simply want to specify CMY 
  623. colours on an RGB display's user interface, but for printing, where any 
  624. kind of colour match between display and print is desired, they are 
  625. totally inaccurate. 
  626.  
  627. If you want to try this kind of thing you're getting into the domain of
  628. colour management systems and should be reading Charle's Poynton's
  629. ColorFAQ.
  630.  
  631. [5.3] HSL and HSV (Hue Saturation and Lightness / Value)
  632.  
  633. Other similar colour spaces include HSI (intensity), HCI (chroma / 
  634. colourfulness), HVC, TSD (hue saturation and darkness) etc etc
  635.  
  636. As linear transforms from RGB they are device dependent, non-linear but very 
  637. intuitive. The separation of the luminance component has some advantages in 
  638. image processing. There appears to be little point in using these 
  639. associated colour spaces, a better alternative is CIELch, which although
  640. more complex offers a more accurate, but equally intuitive way of
  641. specifying colours. 
  642.  
  643. If you think of RGB space as a simple cube, with the red, green and blue
  644. vectors as the three axis and imagine a line drawn through the cube centre
  645. from black (0,0,0) to white (1,1,1) then HSI space is this cube tipped up
  646. onto one corner so that the black - white line is vertical. Then the black
  647. - white line becomes the intensity axis, the hue is given by an angle from
  648. the intensity axis and the saturation is the distance from the central
  649. intensity axis out to the colour point (the radius).
  650. If you only want a simple way of selecting colour on an RGB display the 
  651. following transforms can be useful:
  652.  
  653. RGB to HSI
  654.  
  655.   I = (1/3)(R+G+B)
  656.  
  657.   S = 1 - (3/(R+G+B))*a    where a is the minimum of R, G and B
  658.  
  659.   H = cos^(-1) [(0.5*(R-G)+(R-B)) / ( ((R-G)^2 + (R-B)(G-B))^(0.5) )]
  660.  
  661.     If S = 0, H is meaningless.
  662.     
  663.     If (B/I) > (G/I) then H = 360 - H since H is an angle in degrees we
  664.     then normalise to 0,1 with H=H/360
  665.  
  666. HSI to RGB
  667.  
  668.   First we restore H to degrees with H = 360H
  669.  
  670.   If 0 < H <= 120 then
  671.     
  672.       B = 1/3(1-S)
  673.       R = 1/3(1+(S cos H) / ( cos(60 - H))
  674.       G = 1 - (B+R)
  675.  
  676.   If 120 < H <= 240 then
  677.  
  678.       H = H - 120
  679.       R = 1/3(1-S)
  680.       G = 1/3(1+(S cos H) / ( cos(60 - H))
  681.       B = 1 - (R+G)
  682.  
  683.   If 240 < H <= 360 then
  684.  
  685.       H = H - 240
  686.       G = 1/3(1-S)
  687.       B = 1/3(1+(S cos H) / ( cos(60 - H))
  688.       R = 1 - (G+B)        
  689.  
  690. for details of other HSI related spaces (HSL) see Foley and VanDam -
  691. full reference in section 8.
  692.  
  693. Section [6]   TV and allied non-linear systems
  694.  
  695. All TV standards use non-linear signals, pre-corrected for the non-linear 
  696. transfer characteristic of the display CRT. It is here that the most 
  697. confusion exists, and so this is a VERY important section to understand.
  698.  
  699. A typical CRT has a non-linear voltage-to-light transfer function with a 
  700. power law usually denoted by gamma. The value of gamma is theoretically 
  701. 2.5, but is specified as 2.2 in NTSC systems, 2.8 in PAL systems, and is 
  702. actually nearer to 2.35 for real CRTs. Any signal destined for display on 
  703. a CRT must be distorted by an inverse law. In practice, that is impossible 
  704. because a pure power law has infinite slope (gain) at zero (black). TV 
  705. systems limit the gain near black to a value between 4 and 5 by offsetting 
  706. the power law. This has the side advantage of increasing saturation in a way 
  707. that compensates for the display having a dark surround. For example the 
  708. ITU-BT.709 specification is:-
  709.     
  710.     Volts = (1 + a) * Light ^ (law) - a        for Light > b
  711.     Volts = slope * Light                      for Light <= b
  712.           where a=0.099, law=0.45, b=0.018.
  713.  
  714. and the gain at zero is 4.5. This law is similar to the formula used for L* 
  715. (see above).
  716.  
  717. So for accurate colour calculations, this law (or whichever law was actually 
  718. applied) must be undone to return to linear signals before doing conversions. 
  719. The law should be reapplied to the results to get the drive signals for the 
  720. actual display.
  721.  
  722. A signal that has been gamma-corrected is shown primed (Y', R', G', B' etc). 
  723. In general, undoing the gamma law will return to linear signals, but that 
  724. is not always true, especially with the Y' signal, which is not directly 
  725. related to the CIE Y value. It is a shame that the TV industry used Y' for 
  726. the luminance channel, because it created a great deal of confusion, most 
  727. of which still exists. But careful reading of the following section shows 
  728. the way to performing totally accurate colour calculations using any colour 
  729. system.
  730.  
  731. [6.1] European Y'U'V' (EBU)
  732.  
  733. European TV (PAL and SECAM coded) uses Y'U'V' components. Y' is similar to 
  734. perceived luminance, U' and V' carry the colour information and some 
  735. luminance information and are bipolar (they go negative as well as positive). 
  736. The symbols U and V here are not related to the U and V of CIE YUV (1960).
  737.  
  738. This coding is also used in some 525 line systems with PAL subcarriers, 
  739. particularly in parts of the Americas. The specification here is that of the 
  740. European Broadcasting Union (EBU). Y' has a bandwidth of 5 MHz in Europe, 
  741. 5.5 MHz in UK. The U' and V' signals usually have up to 2.5 MHz bandwidth 
  742. in a component studio system, but can be as little as 600 kHz or less in a 
  743. VHS recorder. U' and V' always have the same bandwidth as each other. The 
  744. CRT gamma law is assumed to be 2.8, but camera correction laws are the same 
  745. as in all other systems (approximately 0.45). The system white point is D65, 
  746. the chromaticity coordinates are:
  747.  
  748.     R:      xr=0.64      yr=0.33
  749.     G:      xg=0.29      yg=0.60
  750.     B:      xb=0.15      yb=0.06
  751.     White:  xn=0.312713  yn=0.329016
  752.  
  753. The conversion equations for linear signals are:-
  754.     X = 0.431*R + 0.342*G + 0.178*B
  755.     Y = 0.222*R + 0.707*G + 0.071*B
  756.     Z = 0.020*R + 0.130*G + 0.939*B
  757.  
  758.     R = 3.063*X - 1.393*Y - 0.476*Z
  759.     G =-0.969*X + 1.876*Y + 0.042*Z
  760.     B = 0.068*X - 0.229*Y + 1.069*Z
  761.  
  762. the coding equations for non-linear signals are:
  763.     Y'= 0.299*R' + 0.587*G' + 0.114*B'
  764.     U'= 0.493*(B' - Y') =-0.147*R' - 0.289*G' + 0.436*B'
  765.     V'= 0.877*(R' - Y') = 0.615*R' - 0.515*G' - 0.100*B'
  766.  
  767.     R'= Y' + 0.000*U' + 1.140*V'
  768.     G'= Y' - 0.396*U' - 0.581*V'
  769.     B'= Y' + 2.029*U' + 0.000*V'
  770.  
  771. The conversion equations between linear 709 RGB signals 
  772. (see later) and EBU RGB signals are:
  773.     Re= 0.9578*R7 + 0.0422*G7 + 0.0000*B7
  774.     Ge= 0.0000*R7 + 1.0000*G7 + 0.0000*B7
  775.     Be= 0.0000*R7 + 0.0118*G7 + 0.9882*B7
  776.  
  777.     R7= 1.0440*Re - 0.0440*Ge + 0.0000*Be
  778.     G7= 0.0000*Re + 1.0000*Ge + 0.0000*Be
  779.     B7= 0.0000*Re - 0.0119*Ge + 1.0119*Be
  780.  
  781.  
  782. [6.2] American Y'I'Q'
  783.  
  784. American TV (NTSC coded) uses Y'I'Q' components. Again Y' is similar to 
  785. perceived luminance, I' and Q' carry colour information and some luminance 
  786. information and are derived by rotating the U'V' vector formed by colour 
  787. coding as described in section 3.1 by 33 degrees. The Y' signal usually has 
  788. 4.2 MHz bandwidth in a 525 line system. Originally the I' and Q' signals 
  789. were to have different bandwidths (0.5 and 1.5 MHz) but they now commonly 
  790. have the same bandwidth (1 MHz). The coding is also used in some 625 line 
  791. countries with NTSC subcarriers, again mostly in the Americas. The CRT 
  792. gamma law is assumed to 2.2. The system white pointis Illuminant C, the 
  793. chromaticity coordinates are:-
  794.     R:      xr=0.67      yr=0.33
  795.     G:      xg=0.21      yg=0.71
  796.     B:      xb=0.14      yb=0.08
  797.     White: xn=0.310063 yn=0.316158 zn=0.373779
  798.  
  799. The conversion equations for linear signals are:-
  800.     X = 0.607*R + 0.174*G + 0.200*B
  801.     Y = 0.299*R + 0.587*G + 0.114*B
  802.     Z = 0.000*R + 0.066*G + 1.116*B
  803.  
  804.     R = 1.910*X - 0.532*Y - 0.288*Z
  805.     G =-0.985*X + 1.999*Y - 0.028*Z
  806.     B = 0.058*X - 0.118*Y + 0.898*Z
  807.  
  808. The coding equations for non-linear signals are:-
  809.     Y'= 0.299*R' + 0.587*G' + 0.114*B'
  810.     I'=-0.27*(B' - Y') + 0.74*(R' - Y') = 0.596*R' - 0.274*G' + 0.322*B'
  811.     Q'= 0.41*(B' - Y') + 0.48*(R' - Y') = 0.212*R' - 0.523*G' - 0.311*B'
  812.  
  813.     R'= Y' + 0.956*I' + 0.621*Q'
  814.     G'= Y' - 0.272*I' - 0.647*Q'
  815.     B'= Y' - 1.105*I' + 1.702*Q'
  816.  
  817. It is possible to define a transformation matrix between EBU Y'U'V' and NTSC 
  818. Y'I'Q'. However, this only makes sense if the primaries are the same for the 
  819. two systems, and clearly they are defined differently. However, over the 
  820. years, the American NTSC system has changed its primaries several times 
  821. until they are now very similar to those of the EBU systems. The non-linear 
  822. connecting equations are:
  823.      I'=-0.27/0.493*U' + 0.74/0.877*V' =-0.547667343*U' +  0.843785633*V'
  824.      Q'= 0.41/0.493*U' + 0.48/0.877*V' = 0.831643002*U' +  0.547320410*V'
  825.  
  826. and:
  827.      U'=-0.546512701*I' +  0.842540416*Q'
  828.      V'= 0.830415704*I' +  0.546859122*Q'
  829.  
  830. To all intents and purposes these equations are identical and so one practical 
  831. set of equations can be used in either direction:
  832.      I'=-0.547*U' + 0.843*V'
  833.      Q'= 0.831*U' + 0.547*V'
  834.  
  835.      U'=-0.547*I' + 0.843*Q'
  836.      V'= 0.831*I' + 0.547*Q'
  837.  
  838. The conversion equations relating NTSC RGB signals to EBU and 709 are:
  839.     Rntsc= 0.6984*Rebu + 0.2388*Gebu + 0.0319*Bebu
  840.     Gntsc= 0.0193*Rebu + 1.0727*Gebu - 0.0596*Bebu
  841.     Bntsc= 0.0169*Rebu + 0.0525*Gebu + 0.8450*Bebu
  842.  
  843.     Rebu= 1.4425*Rntsc - 0.3173*Gntsc - 0.0769*Bntsc
  844.     Gebu=-0.0275*Rntsc + 0.9350*Gntsc + 0.0670*Bntsc
  845.     Bebu=-0.0272*Rntsc - 0.0518*Gntsc + 1.1081*Bntsc
  846.  
  847. and:
  848.     Rntsc= 0.6698*R709 + 0.2678*G709 + 0.0323*B709
  849.     Gntsc= 0.0185*R709 + 1.0742*G709 - 0.0603*B709
  850.     Bntsc= 0.0162*R709 + 0.0432*G709 + 0.8551*B709
  851.  
  852.     R709= 1.5073*Rntsc - 0.3725*Gntsc - 0.0832*Bntsc
  853.     G709=-0.0275*Rntsc + 0.9350*Gntsc + 0.0670*Bntsc
  854.     B709=-0.0272*Rntsc - 0.0401*Gntsc + 1.1677*Bntsc
  855.  
  856. [6.3] SMPTE-C RGB
  857.  
  858. SMPTE-C is the current colour standard for broadcasting in America, the old 
  859. NTSC standard for primaries is no longer in wide use because the primaries 
  860. of the system have gradually shifted towards those of the EBU 
  861. (see section 6.2). In all other respects, SMPTE-C is the same as NTSC. 
  862. The CRT gamma law is assumed to be 2.2. The white point is now D65, and 
  863. the chromaticities are:
  864.  
  865.     R:     xr=0.630     yr=0.340
  866.     G:     xg=0.310     yg=0.595
  867.     B:     xb=0.155     yb=0.070
  868.     White: xn=0.312713  yn=0.329016
  869.  
  870. The conversion equations for linear signals are:
  871.     X = 0.3935*R + 0.3653*G + 0.1916*B
  872.     Y = 0.2124*R + 0.7011*G + 0.0866*B
  873.     Z = 0.0187*R + 0.1119*G + 0.9582*B
  874.  
  875.     R = 3.5058*X - 1.7397*Y - 0.5440*Z
  876.     G =-1.0690*X + 1.9778*Y + 0.0352*Z
  877.     B = 0.0563*X - 0.1970*Y + 1.0501*Z
  878.  
  879. The coding equations for non-linear signals are the same as for NTSC:
  880.     Y'= 0.299*R' + 0.587*G' + 0.114*B'
  881.     I'=-0.27*(B' - Y') + 0.74*(R' - Y') = 0.596*R' - 0.274*G' + 0.322*B'
  882.     Q'= 0.41*(B' - Y') + 0.48*(R' - Y') = 0.212*R' - 0.523*G' - 0.311*B'
  883.  
  884.     R'= Y' + 0.956*I' + 0.621*Q'
  885.     G'= Y' - 0.272*I' - 0.647*Q'
  886.     B'= Y' - 1.105*I' + 1.702*Q'
  887.  
  888. and the same conversion equations work between EBU and SMPTE-C components:
  889.     I'=-0.547*U' + 0.843*V'
  890.     Q'= 0.831*U' + 0.547*V'
  891.  
  892.     U'=-0.547*I' + 0.843*Q'
  893.     V'= 0.831*I' + 0.547*Q'
  894.  
  895. The conversion equations relating SMPTE-C RGB signals to EBU and 709 signals 
  896. are:
  897.     Rsmptec= 1.1123*Rebu - 0.1024*Gebu - 0.0099*Bebu
  898.     Gsmptec=-0.0205*Rebu + 1.0370*Gebu - 0.0165*Bebu
  899.     Bsmptec= 0.0017*Rebu + 0.0161*Gebu + 0.9822*Bebu
  900.  
  901.     Rebu= 0.9007*Rsmptec + 0.0888*Gsmptec + 0.0105*Bsmptec
  902.     Gebu= 0.0178*Rsmptec + 0.9658*Gsmptec + 0.0164*Bsmptec
  903.     Bebu=-0.0019*Rsmptec - 0.0160*Gsmptec + 1.0178*Bsmptec
  904.  
  905. and:
  906.     Rsmptec= 1.0654*R709 - 0.0554*G709 - 0.0010*B709
  907.     Gsmptec=-0.0196*R709 + 1.0364*G709 - 0.0167*B709
  908.     Bsmptec= 0.0016*R709 + 0.0044*G709 + 0.9940*B709
  909.  
  910.     R709= 0.9395*Rsmptec + 0.0502*Gsmptec + 0.0103*Bsmptec
  911.     G709= 0.0178*Rsmptec + 0.9658*Gsmptec + 0.0164*Bsmptec
  912.     B709=-0.0016*Rsmptec - 0.0044*Gsmptec + 1.0060*Bsmptec
  913.  
  914. [6.4] ITU.BT-601 Y'CbCr
  915.  
  916. This is the international standard for digital coding of TV pictures at 525 
  917. and 625 line rates. It is independent of the scanning standard and the 
  918. system primaries, therefore there are no chromaticity coordinates, no CIE 
  919. XYZ matrices, and no assumptions about white point or CRT gamma. It deals 
  920. only with the digital representation of R'G'B' signals in Y'CbCr form. 
  921. The non-linear coding matrices are:
  922.  
  923.     Y'= 0.299*R' + 0.587*G' + 0.114*B'
  924.     Cb=-0.169*R' - 0.331*G' + 0.500*B'
  925.     Cr= 0.500*R' - 0.419*G' - 0.081*B'
  926.  
  927.     R'= Y' + 0.000*U' + 1.403*V'
  928.     G'= Y' - 0.344*U' - 0.714*V'
  929.     B'= Y' + 1.773*U' + 0.000*V'
  930.  
  931.  
  932. [6.5] ITU.BT-709 HDTV studio production in Y'CbCr
  933.  
  934. This is a recent standard, defined only as an interim standard for HDTV 
  935. studio production. It was defined by the CCIR (now the ITU) in 1988, but is 
  936. not yet recommended for use in broadcasting. The primaries are the R and B 
  937. from the EBU, and a G which is midway between SMPTE-C and EBU. The CRT gamma 
  938. law is assumed to be 2.2. White is D65. The chromaticities are:
  939.     R:      xr=0.64       yr=0.33
  940.     G:      xg=0.30       yg=0.60
  941.     B:      xb=0.15       yb=0.06
  942.     White:  xn=0.312713   yn=0.329016
  943.  
  944. The conversion equations for linear signals are:
  945.     X = 0.412*R + 0.358*G + 0.180*B
  946.     Y = 0.213*R + 0.715*G + 0.072*B
  947.     Z = 0.019*R + 0.119*G + 0.950*B
  948.  
  949.     R = 3.241*X - 1.537*Y - 0.499*Z
  950.     G =-0.969*X + 1.876*Y + 0.042*Z
  951.     B = 0.056*X - 0.204*Y + 1.057*Z
  952.  
  953. The coding equations for non-linear signals are:
  954.     Y'= 0.2215*R' + 0.7154*G' + 0.0721*B'
  955.     Cb=-0.1145*R' - 0.3855*G' + 0.5000*B'
  956.     Cr= 0.5016*R' - 0.4556*G' - 0.0459*B'
  957.  
  958.     R'= Y' + 0.0000*Cb + 1.5701*Cr
  959.     G'= Y' - 0.1870*Cb - 0.4664*Cr
  960.     B'= Y' - 1.8556*Cb + 0.0000*Cr
  961.  
  962. The conversion equations between linear 709 RGB signals and EBU RGB signals 
  963. are:
  964.     Re= 0.9578*R7 + 0.0422*G7 + 0.0000*B7
  965.     Ge= 0.0000*R7 + 1.0000*G7 + 0.0000*B7
  966.     Be= 0.0000*R7 + 0.0118*G7 + 0.9882*B7
  967.  
  968.     R7= 1.0440*Re - 0.0440*Ge + 0.0000*Be
  969.     G7= 0.0000*Re + 1.0000*G7 + 0.0000*Be
  970.     B7= 0.0000*Re - 0.0119*Ge + 1.0119*Be
  971.  
  972.  
  973. [6.6] SMPTE-240M Y'PbPr
  974.  
  975. This one of the developments of NTSC component coding, in which the B primary
  976. and white point were changed. The CRT gamma law is assumed to be 2.2. The 
  977. white point is D65, chromaticity coordinates are:
  978.     R:      xr=0.67     yr=0.33
  979.     G:      xg=0.21     yg=0.71
  980.     B:      xb=0.15     yb=0.06
  981.     White:  xn=0.312713 yn=0.329016
  982.  
  983. The conversion equations for linear signals are:
  984.     X = 0.567*R + 0.190*G + 0.193*B
  985.     Y = 0.279*R + 0.643*G + 0.077*B
  986.     Z = 0.000*R + 0.073*G + 1.016*B
  987.  
  988.     R = 2.042*X - 0.565*Y - 0.345*Z
  989.     G =-0.894*X + 1.815*Y + 0.032*Z
  990.     B = 0.064*X - 0.129*Y + 0.912*Z
  991.  
  992. The coding equations for non-linear signals are:
  993.    Y'= 0.2122*R' + 0.7013*G' + 0.0865*B'
  994.    Pb=-0.1162*R' - 0.3838*G' + 0.5000*B'
  995.    Pr= 0.5000*R' - 0.4451*G' - 0.0549*B'
  996.  
  997.    R'= Y + 0.0000*Pb + 1.5756*Pr
  998.    G'= Y - 0.2253*Pb + 0.5000*Pr
  999.    B'= Y + 1.8270*Pb + 0.0000*Pr
  1000.  
  1001. The conversion equations relating SMPTE 240 RGB to EBU and 709 primaries are:
  1002.     R240= 0.7466*Re + 0.2534*Ge + 0.0000*Be
  1003.     G240= 0.0187*Re + 0..9813*Ge + 0.0000*Be    
  1004.     B240= 0.0185*Re + 0.0575*Ge + 0.9240*Be
  1005.  
  1006.     Re= 1.3481*R240 - 0.3481*G240 + 0.0000*B240
  1007.     Ge=-0.0257*R240 + 1.0257*G240 + 0.0000*B240
  1008.     Be=-0.0254*R240 - 0.0568*G240 + 1.0822*B240
  1009.  
  1010. and:
  1011.     R240= 0.7151*R709 + 0.2849*G709 + 0.0000*B709
  1012.     G240= 0.0179*R709 + 0.9821*G709 + 0.0000*B709
  1013.     B240= 0.0177*R709 + 0.0472*G709 + 0.9350*B709
  1014.  
  1015.     R709= 1.4086*R240 - 0.4086*G240 + 0.0000*B240
  1016.     G709=-0.0257*R240 + 1.0457*G240 + 0.0000*B240
  1017.     B709=-0.0254*R240 - 0.0440*G240 + 1.0695*B240
  1018.  
  1019.  
  1020. [6.7] Kodak PhotoYCC colour space for PhotoCD images.
  1021.  
  1022. The Kodak PhotoYCC colour space was designed for encoding images with the 
  1023. PhotoCD system. It is based on both CCIR Recommendations 709 and 601-1, 
  1024. having a colour gamut defined by the CCIR 709 primaries and a luminance 
  1025. - chrominance representation of colour like CCIR 601-1's YCbCr. 
  1026.  
  1027. To encode data, a transfer function (gamma correction) is first applied;
  1028.  
  1029. For R,G,B > 0.018
  1030. R' = 1.099*R ^0.45 - 0.099
  1031. G' = 1.099*G ^0.45 - 0.099
  1032. B' = 1.099*B ^0.45 - 0.099
  1033.  
  1034. For R,G,B, <= 0.018
  1035. R' = 4.5*R
  1036. G' = 4.5*G
  1037. B' = 4.5*B
  1038.  
  1039. Secondly the R'G'B' data is transformed into PhotoYCC data, 
  1040.  
  1041.     Luma    = 0.299R'  + 0.587G' + 0.114B'
  1042.     Chroma1 = -0.299R' - 0.587G' + 0.886B'
  1043.     Chroma2 = 0.701R'  - 0.587G' - 0.114B'
  1044.  
  1045. Finally the floating point values are stored as 8 bit integers;
  1046.  
  1047.     Luma_8bit       = (255 / 1.402)Luma
  1048.     Chroma1_8bit    = 111.40*Chroma1 + 156
  1049.     Chroma2_8bit    = 135.64*Chroma2 + 137
  1050.  
  1051. The unbalanced scale difference between Chroma1 and Chroma2 is designed, 
  1052. according to Kodak, to follow the typical distribution of colours in 
  1053. real scenes.
  1054.  
  1055. Kodak YCC can store more information than current display devices can cope 
  1056. with (it allows negative RGB values), the transforms from YCC to RGB are 
  1057. therefore not simply the inverse of RGB to YCC, they depend on the target 
  1058. display system.
  1059.  
  1060. Converting PhotoYCC data to RGB 24bit data for display by computers on CRT's 
  1061. is achieved as follows;
  1062.  
  1063. Firstly normal Luma and Chroma data are recovered;
  1064.  
  1065.     Luma            = 1.3584 * Luma_8bit
  1066.     Chroma1         = 2.2179 * (Chroma1_8bit - 156)
  1067.     Chroma2         = 1.8215 * (Chroma2_8bit - 137)
  1068.  
  1069. For display primaries that are, or are very close to, CCIR 
  1070. Recommendation 709 primaries in their chromaticities, then 
  1071.  
  1072.     R'      = L + Chroma2
  1073.     G'      = L - 0.194Chroma1 - 0.509Chroma2
  1074.     B'      = L + Chroma1
  1075. Two things to watch are;
  1076.  
  1077. a) this results in RGB values from 0 to 346 (instead of the more usual 0 to 
  1078. 255) a look-up-table is usually used to convert these through a non-linear 
  1079. function to 8 bit data. For example;
  1080.  
  1081.     Y  = (255/1.402)*Y'                                 
  1082.     C1 = 111.40*C1'+156                                 
  1083.     C2 = 135.64*C2'+137 
  1084.  
  1085. b) if the display phosphors differ from CCIR 709 primaries then further 
  1086. conversion will be necessary, possibly through an intermediate device 
  1087. independent colour space such as CIE XYZ.
  1088.  
  1089. Converting stored PhotoYCC data to RGB signal voltages for display on  
  1090. television's is achieved as follows;
  1091.  
  1092. Firstly  normal Luma and Chroma data are recovered;
  1093.  
  1094.     Luma            = 1.3584 * Luma_8bit
  1095.     Chroma1         = 2.2179 * (Chroma1_8bit - 156)
  1096.     Chroma2         = 1.8215 * (Chroma2_8bit - 137)
  1097.  
  1098. the RGB display voltages are then as follows;
  1099.  
  1100.     R'      = (L + Chroma2) / 353.2
  1101.     G'      = (L - 0.194Chroma1 - 0.509Chroma2) / 353.2
  1102.     B'      = (L + Chroma1) / 353.2
  1103.  
  1104. Note, the gamma corrected RGB values (R'G'B') are fine so long as you haven't
  1105. done anything silly - like calibrate you CRT for linear luminance :)
  1106.  
  1107. Section [7] Colour appearence.
  1108.  
  1109. When a colour is measured using the CIE system it can be defined in such a
  1110. way that it can be reproducted exactly. This is because the CIE system
  1111. defines the conditions and mechanism of the measurement of a colour, for
  1112. example the exact type of illumination and geometry is specified. However,
  1113. even though a colour has set CIE co-ordinates, it will still appear to
  1114. an observer to be different as its surround or the ambient lighting change.
  1115. This has serious consequences for digital colour spaces. For example
  1116. when printing the conversion from RGB to CMY(K) may be perfect but the
  1117. viewing conditions of the screen and hard copy will be different. The
  1118. display may have a white point of around 8000k with ambient lighting
  1119. provided by fluorescent tubes while the print may by displayed in a 
  1120. tungsten lit gallerey - oh dear! So although you may have a colour
  1121. match in terms of CIE co-ordinates, the colours may _appear_ to differ.
  1122.  
  1123. There is a possible solution, but it is complex so a brief summary only is 
  1124. given here. Essentially a colour appearence space (as opposed to a simple
  1125. colour space) is required. There are a few of these around, for example
  1126. Hunt's colour appearence space with is based on his model of colour vision
  1127. and is explained in his book "Measuring Colour". Hunt's model is designed
  1128. to predict the appearence of a colour under different viewing conditions
  1129. based on colorimetry of five different regions of the visible scene.
  1130.  
  1131. Section [8] The references and bedtime reading.
  1132.  
  1133. [*]'ed are recommended.
  1134.  
  1135.    Notes on conversion between RGB pixel values and CIE co-ordinates.
  1136.  
  1137. "Calibration of a computer controlled color monitor", Brainard, D.H, Color 
  1138. Research & Application, 14, 1, pp 23-34 (1989).
  1139.  
  1140. "An inexpensive scheme for calibration of a colour monitor in terms of CIE
  1141. standard coordinates" W.B. Cowan, Computer Graphics, Vol. 17 No. 3, 1983.
  1142.  
  1143. [*] "CRT Colorimetry:Part 1 Theory and Practice, Part 2 Metrology", Berns,
  1144. R.S., Motta, R.J. and Gorzynski, M.E., Color Research and Application, 18, 
  1145. (1993). 
  1146.  
  1147.    Standard references on colour science.
  1148.  
  1149. "CIE Colorimetry" Official recommendations of the International Commission
  1150.  on Illumination, Publication 15.2 1986
  1151.  
  1152. [*] "The Reproduction of Colour in Photography, Printing and Television", 
  1153. R.W.G. Hunt, Fountain Press, Tolworth, England, 1987
  1154.  
  1155. [*] "Measuring Colour" second edition, R.W.G. Hunt, Ellis Horwood 1991.
  1156.  
  1157.    References specific to colour in television and in computers.
  1158.  
  1159. [*] "Colour Science in Television and Display Systems" Sproson, W, N, 
  1160. Adam Hilger Ltd, 1983. ISBN 0-85274-413-7
  1161.  
  1162. [*] "Effective Color Displays. Theory and Practice", Travis, D, Academic Press,
  1163. 1991. ISBN 0-12-697690-2
  1164. This contains C source code for many colour space conversions.  
  1165.  
  1166.  
  1167. [pearson]
  1168.  
  1169. [computer generated colour]
  1170.  
  1171.    Colour and printing.
  1172.  
  1173. Field, G.G., Color and Its Reproduction, Graphics Arts Technical
  1174. Foundation, 1988, pp. 320-9  (Read this about CMY/CMYK)
  1175.  
  1176.    Display non-linearity and gamma.
  1177.  
  1178. [*] "Gamma and its disguises: The nonlinear mappings of intensity in
  1179. perception, CRT's, Film and Video" C. A. Poynton, SMPTE Journal, December 
  1180. 1993
  1181.  
  1182.    Colour in Digital Image Processing and Computer Graphics.
  1183.  
  1184. "Digital Image Processing", Rafael C. Gonzalez and Richard E. Woods,
  1185. Addision Wesley, 1992. Chapter 4.6
  1186.  
  1187. "Fundamentals of Digital Image Processing", Anil K. Jain, Prentice-Hall
  1188. International, 1989. Chapter 3.
  1189.  
  1190. "Computer graphics : principles and practices" James D. Foley, et al. 
  1191. 2nd ed. Addison-Wesley, c1990. 
  1192.  
  1193.    Others.
  1194.  
  1195. "On the Gun Independence and Phosphor Consistency of Color Video Monitors"
  1196. W.B. Cowan N. Rowell, Color Research and Application, V.11 Supplement 1986
  1197.  
  1198. "Precision requirements for digital color reproduction" M Stokes
  1199. MD Fairchild RS Berns, ACM Transactions on graphics, v11 n4 1992
  1200.  
  1201. "The colorimetry of self luminous displays - a bibliography" CIE
  1202. Publication n.87, Central Bureau of the CIE, Vienna 1990
  1203.  
  1204. "Fully Utilizing Photo CD Images, Article No. 4, 
  1205. PhotoYCC Colour Encoding and Compression Schemes" Eastman Kodak Company, 
  1206. Rochester NY (USA) (1993).
  1207.  
  1208.    On-line references and links.
  1209.  
  1210. CIE
  1211.    http://www.hike.te.chiba-u.ac.jp/ikeda/CIE/home.html
  1212.  
  1213. Charles Poynton's Color and Gamma FAQ page
  1214.    http://www.inforamp.net/~poynton/Poynton-colour.html
  1215.  
  1216. University of Derby, Colour Research Group. (RWG Hunt)
  1217.    http://ziggy.derby.ac.uk:80/colour/
  1218.  
  1219. This document
  1220.    ftp://ftp.wmin.ac.uk/pub/itrg/coloureq.txt
  1221.    or via http://www.wmin.ac.uk/ITRG
  1222.  
  1223. Section [8] Footnotes & Disclaimer.
  1224.  
  1225. Thanks to everyone who contributed, especially to Charles Poynton 
  1226. (poynton@inforamp.net) and David Wooding (wdrdsw@cardiff.ac.uk) for 
  1227. helpful comments. Feel free to send comments, suggestions, additions, 
  1228. flames, etc to ajoec1@wmin.ac.uk.
  1229.  
  1230. Bits to add.
  1231.  
  1232.  Proper details of CMY(K) conversions
  1233.  Colour Management Systems
  1234.  Gamut Mapping
  1235.  Add your topics here!
  1236.  
  1237. If we've made any mistakes, please let us know, however we take no
  1238. reponsibility for them. Opinions expressed are not those of either
  1239. the British Broadcasting Corporation nor the University of Westminster.
  1240. -----------------------------------------------------------------------
  1241.